<template>
  <div class="index">
    <!-- 容器区域 -->
    <el-container>
        <!-- 头部 -->
        <el-header>
            <h3 class="h_text">后台管理系统</h3>
            <el-dropdown @command="changeMenu">
            <span class="el-dropdown-link">
                {{userName}}<i class="el-icon-arrow-down el-icon-setting"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="a">退出</el-dropdown-item>
                <el-dropdown-item command="b">修改信息</el-dropdown-item>
            </el-dropdown-menu>
            </el-dropdown>  
        
         <!-- 切换主题 -->
                <el-dropdown @command="changeTheme">
                    <span class="el-dropdown-link">
                        切换主题<i class="el-icon-arrow-down el-icon-dropdown"></i>
                    </span>
                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item command="blue">天蓝色</el-dropdown-item>
                        <el-dropdown-item command="orange">深黄色</el-dropdown-item>
                        <el-dropdown-item command="pink">死亡粉</el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
            </el-header>
        <!-- 中间内容 -->
        <el-container>
            <!-- 左侧菜单栏区域 -->
            <el-aside width="200px">
                 <el-col>
                    <el-menu
                    class="el-menu-vertical-demo"
                    background-color="#545c64"
                    text-color="#fff"
                    active-text-color="#ffd04b"
                    router
                    >
                    <!-- 后台默认首页功能菜单 -->
                            <el-submenu index="0">
                                <template slot="title">
                                    <i class="el-icon-s-home"></i>
                                    <span>网站设置</span>
                                </template>
                                <el-menu-item-group>
                                    <el-menu-item index="/home">基本设置</el-menu-item>
                                </el-menu-item-group>
                            </el-submenu>
                            
                        <!-- 菜单组1 -->
                        <el-submenu 
                            v-for="item in menus"
                            :key="item.id"
                            :index="item.id+''">
                            <!-- 菜单一级标题 -->
                            <template slot="title">
                            <i :class="item.icon"></i>
                            <span>{{item.title}}</span>
                            </template>
                            <!-- 菜单二级标题 -->
                            <el-menu-item-group
                                v-for="m in item.children"
                                :key="m.id"
                            >
                            <el-menu-item :index="m.url">{{m.title}}</el-menu-item>
                            </el-menu-item-group> 
                        </el-submenu>
                        
                    </el-menu>
                </el-col>
            </el-aside>
            <!-- 右侧内容区域 -->
            <el-main>
                <el-breadcrumb separator-class="el-icon-arrow-right">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>{{$route.meta.title}}</el-breadcrumb-item>
                </el-breadcrumb>
                <!-- 二级路由出口 -->
                <router-view></router-view>
            </el-main>
            
        </el-container>
    </el-container>
  </div>
</template>

<script>
import editeTheme from '../../utils/theme/index'
import {mapActions} from 'vuex'
export default {

  data() {
    return {
        userName:"",//管理员账号
        menus:[],//管理员菜单权限列表数据
    };
  },
   mounted(){
        let {menus,username} = JSON.parse(localStorage.getItem('userInfo')) 
        this.userName = username
        this.menus = menus

        //获取缓存中的主题
        editeTheme(localStorage.getItem('themeName') || 'blue')

        
    },
  methods: {
    ...mapActions({
        userLoginOut:"login/userLoginOut"
    }),
    //1.监听用户点击下拉菜单操作
    changeMenu(info){
        info=="a"? this.loginOut():this.editUserInfo()
    },

    

    //2.用户退出登录
    loginOut(){
        this.userLoginOut(this)
      },
    //3.用户编辑信息
    editUserInfo(){

    },
     // 4.切换主题
        changeTheme(themeName){
           editeTheme(themeName)
        }
  },
};
</script>

<style scoped lang="less">
@import "../../assets/less/theme.less";
/* 布局样式 */
.index,.el-container{
        width: 100vw;
        height: 100vh;
    }
/* 头部布局样式区域 */
 .el-header{
    background-color: @--header-bg-color;
    color: #333;
    line-height: 60px;
    position: relative;
  }
 /* 头部右侧用户信息样式 */
    .el-header .el-dropdown:nth-of-type(1){
        position: absolute;
        right: 40px;
    }
    .el-header .el-dropdown:nth-of-type(2){
        position: absolute;
        right: 140px;
    }
    /* 头部左侧标题样式 */
    .el-header .header_title{
        position: absolute;
        left: 20px;
    }
    
    /* 左侧菜单栏样式区域 */
    .el-aside {
        background-color: #545c64;
        color: #333;
        line-height: 200px;
        overflow: hidden;
    }
  ul{
    width: 200px;
  }
  
  /* 右侧内容布局样式区域 */
  .el-main {
    background-color: #E9EEF3;
    color: #333;
  }
</style>
